from django.db import models
# 导入院系和专业的类
from basicweb.models import Faculty, Major

# === 学生信息 ===
# 包含的信息：学号，姓名，性别，出生日期，手机号码，邮箱地址，家庭住址，所在院系，所在专业，入学时间，状态
class Student(models.Model):
    sno = models.CharField(verbose_name="学号", primary_key=True, max_length=100, null=False)
    name = models.CharField(verbose_name='姓名', max_length=100)
    gender = models.CharField(verbose_name="性别", max_length=100)
    birthday = models.DateField(verbose_name="出生日期")
    mobile = models.CharField(verbose_name="手机号码", max_length=100)
    email = models.EmailField(verbose_name="邮箱地址", max_length=100)
    address = models.CharField(verbose_name='家庭住址', max_length=200)
    faculty = models.ForeignKey(verbose_name="所属院系", to=Faculty, on_delete=models.PROTECT)
    major = models.ForeignKey(verbose_name="所学专业", to=Major, on_delete=models.PROTECT)
    start_date = models.DateField(verbose_name="入学时间")
    status = models.CharField(verbose_name="状态", max_length=100, choices=(
        ('在校', '在校'), ('毕业', '毕业'), ('休学', '休学'), ('开除', '开除')), default='在校')

    class Meta:
        managed = True
        app_label = "studentweb"
        db_table = "Stu_Student"
        verbose_name = "Student"
        verbose_name_plural = "Student"

    def __str__(self):
        return "%s" % (self.name)


# 学生管理--> 学生照片
# 字段：Id [yyyymmddHHMMSS + 4位随机值]， url（图片url ）, Create_time (上传时间)
class StudentImage(models.Model):
    id = models.CharField(verbose_name="编号", max_length= 20, primary_key=True, null=False, blank=False)
    url = models.CharField(verbose_name="URL路径", max_length=200, null=True, blank=True, default=None)
    title = models.CharField(verbose_name="标题", max_length=20, null=True, blank=True, default=None)
    remark = models.CharField(verbose_name="标注", max_length=200, null=True,blank=True, default=None)
    create_time = models.DateTimeField(verbose_name="上传时间",null=True, blank=True, default=None)

    class Meta:
        managed = True
        app_label = "studentweb"
        db_table = "Stu_StudentImage"
        verbose_name = "Stu_StudentImage"
        verbose_name_plural = "Stu_StudentImage"
